package com.metagurukul.informer.utility;
import java.io.FileInputStream;
import java.sql.*;
import java.util.Properties;

public class ConnectionFactory{
	private Connection con;
	private ConnectionFactory(){
		try{
			/*Properties prop = new Properties();
               //load a properties file
    		prop.load(new FileInputStream(".\\config.properties"));
			String connectionURL=prop.getProperty("dburl");
			String dbUsername=prop.getProperty("dbpassword");
			String dbPassword=prop.getProperty("dbpassword");
			*/
			
			String connectionURL="jdbc:mysql://localhost:3306/informer";
			//String connectionURL="jdbc:mysql://mysql-metainformer.jelastic.servint.net/informer";
			String dbUsername="root";
			String dbPassword="root";
			//String dbPassword="0KyWdNZCq2";
			String dbdriver="com.mysql.jdbc.Driver";
			Class.forName(dbdriver);
			con = DriverManager.getConnection(connectionURL, dbUsername, dbPassword); 
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	/**
	 * @return connection to database
	 */
	public static Connection getInstance(){
		return new ConnectionFactory().con;
	}
	public void finalize(){
		try{
			if(con!=null){
				con.close();			
			}
		   }
		catch(Exception e){
		}	
	}
}